package com.up.blog.service;


import com.up.blog.controller.ArticleController;
import com.up.blog.controller.GetDraftController;
import com.up.blog.domain.Articlebean;
import com.up.blog.domain.PageInfo;
import com.up.blog.mapper.GetArticlesMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@Service("getArticlesService")
public class GetArticlesService{
//    InputStream conf = Resources.getResourceAsStream("SqlMapConfig.xml");
//    //创建会话工厂
//    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(conf);
//    //使用会话工厂创建会话对象
//    SqlSession sqlSession = sqlSessionFactory.openSession(true);
//    GetArticlesMapper mapper = sqlSession.getMapper(GetArticlesMapper.class);
    @Autowired
    private  GetArticlesMapper mapper;
    public GetArticlesService() throws IOException {
    }

    public Long getDraftCount() throws SQLException {
        return mapper.getDraftCount();
    }
    public Long getMarkCount() throws SQLException {
        return mapper.getMarkCount();
    }
    public Long getCount() throws SQLException {
        return mapper.getCount();
    }
    public List<Articlebean> getArticlebean() throws SQLException {
        Integer curCount=(ArticleController.page-1)*ArticleController.limit;
        PageInfo pageInfo=new PageInfo();
        pageInfo.setCurCount(curCount);
        pageInfo.setLimit(ArticleController.limit);
       List<Articlebean> res=mapper.getArticlebean(pageInfo);
       System.out.println(res);
        return res;
    }
    public List<Articlebean> getdraftArticlebean() throws SQLException {
        Integer curCount=(GetDraftController.page-1)*GetDraftController.limit;
        PageInfo pageInfo=new PageInfo();
        pageInfo.setCurCount(curCount);
        pageInfo.setLimit(ArticleController.limit);
        return mapper.getdraftArticlebean(pageInfo);
    }
    public List<Articlebean> getMarkArticlebean() throws SQLException {
        Integer curCount=(ArticleController.page-1)*ArticleController.limit;
        PageInfo pageInfo=new PageInfo();
        pageInfo.setCurCount(curCount);
        pageInfo.setLimit(ArticleController.limit);
        return mapper.getMarkArticlebean(pageInfo);
    }
    public int draftpublish(String id) throws SQLException {
       return mapper.draftpublish(id);
    }

}